<template>
  <div>
    <button @click="showModelView = true">弹出model框</button>
    <!-- teleport是vue中自带的一个组件，to是一个选择器，指向要声明的父节点 -->
    <teleport to="body">
      <div class="modelview" v-if="showModelView">
        <div>
          这是一个弹出框
          <div>父元素是body</div>
          <button @click="showModelView = false">关闭弹框</button>
        </div>
      </div>
    </teleport>
  </div>
</template>
<script>
import { ref } from "vue";
export default {
  setup() {
    const showModelView = ref(false);
    return {
      showModelView,
    };
  },
};
</script>
<style  scoped>
.modelview {
  position: absolute;
  bottom: 0;
  right: 0;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  background-color: rgba(0, 0, 0, 0.5);
}
.modelview > div {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  width: 300px;
  height: 400px;
  border: 1px solid red;
  background-color: white;
}
</style>